const fs = require('fs')
const path = require('path')
const Generator = require('yeoman-generator')

module.exports = class BaseGenerator extends Generator {
  preventLoadInGeneratorDir () {
    let current = path.resolve('.')

    while (true) {
      const file = path.resolve(current, '.yo-generator')
      if (fs.existsSync(file)) {
        this.log('不允许在 generator 源代码下初始化脚手架')
        process.exit(1)
      } else if (current === '/') {
        break
      } else {
        current = path.resolve(current, '..')
      }
    }
  }
}
